package team.helpmephone.app.set.record;

import team.helpmephone.app.R;
import team.helpmephone.app.common.DaoHelpMePhone;
import android.app.ListActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ActivitySetRecordTime extends ListActivity {

	/** Called when the activity is first created. */
	private DaoHelpMePhone dao;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		initialize();

	}

	private void initialize() {
		dao = DaoHelpMePhone.getInstance();
		ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this, R.array.time_items, android.R.layout.simple_spinner_item);

		setListAdapter(adapter);
		getListView().setTextFilterEnabled(true);
		getListView().setBackgroundColor(Color.WHITE);

	}

	protected void onListItemClick(ListView l, View v, int position, long id) {
		String spinnerItem = l.getItemAtPosition(position).toString();
		if (dao.set(this, spinnerItem)) {
			Toast.makeText(this, R.string.db_update_success, Toast.LENGTH_SHORT).show();
		} else {
			Toast.makeText(this, R.string.db_update_failure, Toast.LENGTH_SHORT).show();
		}
	}

}
